﻿/********************************************************************
* Copyright (C) 2012 iTouch, Inc (http://www.itouch.com.cn) 
* All rights reserved
* Created by ZhuDongDong <dongdong_82975389@163.com> at 2012-3-31 22:15:28

* 版权所有：浙大网新易盛网络通讯有限公司
* 文件名称：ExpressCompanyDal
* 作    者：朱冬冬(dongdong_82975389@163.com)
* 创建时间：2012-3-31 22:15:28
* 说    明：
*
********************************************************************
$Id: ExpressCompanyDal.cs 114 2012-04-02 02:19:19Z skyz980@gmail.com $
$Rev: 114 $ 
$Author: skyz980@gmail.com $ 
$Date: 2012-04-02 02:19:19 +0000 (Mon, 02 Apr 2012) $
*********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernateBusiness.Data;
using Model;
using IDb;

namespace DataDeal
{
    public class ExpressCompanyDal : IExpressCompany
    {
        private INHibernateHelper _helper;
        public ExpressCompanyDal()
        {
            _helper = NHibernateFactory.Instance.GetDataHandler();
        }


        #region IExpressCompany 成员

        public bool Save(ExpressCompany entity)
        {
            bool result;
            try
            {
                _helper.Save(entity);
                result = true;
            }
            catch
            {
                result = false;
            }
            return result;
        }

        public bool Update(ExpressCompany entity)
        {
            try
            {
                _helper.Update(entity);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public IList<ExpressCompany> GetAll()
        {
            try
            {
                return _helper.GetQuery<ExpressCompany>();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }

        public bool Delete(string id)
        {
            try
            {
                _helper.Delete(string.Format("delete from ExpressCompany where Id='{0}'",id));
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Delete(ExpressCompany entity)
        {
            try
            {
                _helper.Delete<ExpressCompany>(entity);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public ExpressCompany GetOneById(string id)
        {
            try
            {
                return _helper.GetQueryById<ExpressCompany>(id);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        #endregion
    }
}